<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2020/1/13
 * Time: 10:42
 */

namespace app\common\service;


class ServerMiddleware
{
    /**
     * @name 中间键管理列表
     * @param $params
     * @param $limit
     * @return \think\Paginator
     * @author wx
     * @date 2020/1/13 10:50
     */
    function list($params, $limit)
    {
        $db = db('server_middleware')
            ->where('is_module', $params['is_module']);

        if(isset($params['type']) && !empty($params['type'])){
            $db->where('type', $params['type']);
        }
        if(isset($params['version']) && !empty($params['version'])){
            $db->where('version', 'like','%'.$params['version'].'%');
        }
        if(isset($params['name']) && !empty($params['name'])){
            $db->where('name', 'like','%'.$params['name'].'%');
        }
        if(isset($params['ip']) && !empty($params['ip'])){
            $db->where('ip', 'like','%'.$params['ip'].'%');
        }
        if(isset($params['desc']) && !empty($params['desc'])){
            $db->where('desc', 'like','%'.$params['desc'].'%');
        }

        $list = $db->order('id desc')->paginate($limit)->toArray();

        return $list;
    }

    /**
     * @name 查找数据
     * @param $condition
     * @author wx
     * @date 2020/1/13 13:45
     */
    function findData($condition)
    {
        return db('server_middleware')->where($condition)->find();
    }

    function modify($condition, $UpdateData)
    {
        return db('server_middleware')->where($condition)->update($UpdateData);
    }

    function add($addData)
    {
        return db('server_middleware')->insert($addData);
    }
}